package com.karry.yl;


import com.karry.commons.DruidDataSourceFactory;
import com.karry.commons.service.OpenIdService;
import org.ponly.fs.FileSystem;
import org.ponly.fs.FileSystems;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

/**
 * @author Administrator
 */
@SpringBootApplication
@PropertySource("classpath:config.properties")
@EnableTransactionManagement
public class Application {

	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}


	/**
	 * druid数据源
	 * @return
	 */
	@Bean
	public DataSource dataSource(){
		return DruidDataSourceFactory.createDataSource();
	}

	/**
	 * fs 模块配置
	 * @param environment
	 * @return
	 */
	@Bean
	public FileSystem fileSystem(Environment environment){
		return FileSystems.getFileSystem(environment.getProperty("fs.url"));
	}

	/**
	 * 威富通 支付Service
	 * @param environment
	 * @return
	 */
	@Bean
	public OpenIdService openIdService(Environment environment){
		OpenIdService.secret = environment.getProperty("xcx.secret");
		OpenIdService.appid = environment.getProperty("xcx.appid");
		OpenIdService.grant_type = environment.getProperty("xcx.grant_type");
		OpenIdService.req_url = environment.getProperty("xcx.req_url");
		return new OpenIdService();
	}


}
